package com.bw.module_home.marketer.model

import com.bw.lib_common.entity.Res
import com.bw.module_home.marketer.api.MarketersApiService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

//class MarketersRepository:BaseRepository<MarketersApiService>() {
//    override fun createApiServer(): MarketersApiService=OkHttpClientManager.retrofitInstance.create(MarketersApiService::class.java)

//    suspend fun getBusinessProfileList(): Res<BusinessProfileEntity> {
//        return createApiServer().getBusinessProfileList()
//    }
//    suspend fun getBusinessProfileDetailById(id:Int): Res<BusinessProfileEntityItem> {
//        return createApiServer().getBusinessProfileDetailById(id)
//    }
//    suspend fun getResidencyApplicationList(): Res<ResidencyApplicationEntity> {
//        return createApiServer().getResidencyApplicationList()
//    }
//    suspend fun addResidencyApplication(residencyApplicationEditEntity: ResidencyApplicationEditEntity): Res<ResidencyApplicationEntityItem> {
//        return createApiServer().addResidencyApplication(residencyApplicationEditEntity)
//    }
//    suspend fun getResidencyApplicationDetailById(id:Int): Res<ResidencyApplicationEntityItem> {
//        return createApiServer().getResidencyApplicationDetailById(id)
//    }
//    suspend fun approveResidencyApplication(id:Int): Res<ResidencyApplicationEntityItem> {
//        return createApiServer().approveResidencyApplication(id)
//    }
//}
class MarketersRepository @Inject constructor() {
    @Inject
    @MarketersModule.CommonHomeApi
    lateinit var api: MarketersApiService

    fun getBusinessProfileList(): Flow<Res<BusinessProfileEntity>> = flow {
        emit(api.getBusinessProfileList())
    }.flowOn(Dispatchers.IO)
    fun addBusinessProfile(businessProfileEntity: BusinessProfileEntityItem): Flow<Res<BusinessProfileEntityItem>> = flow {
        emit(api.addBusinessProfile(businessProfileEntity))
    }.flowOn(Dispatchers.IO)

    fun deleteBusinessProfile(id: Int): Flow<Res<Boolean>> = flow {
        emit(api.deleteBusinessProfile(id))
    }.flowOn(Dispatchers.IO)
    fun getBusinessProfileDetailById(id: Int): Flow<Res<BusinessProfileEntityItem>> = flow {
        emit(api.getBusinessProfileDetailById(id))
    }.flowOn(Dispatchers.IO)
    fun getResidencyApplicationList(): Flow<Res<ResidencyApplicationEntity>> = flow {
        emit(api.getResidencyApplicationList())
    }.flowOn(Dispatchers.IO)
    fun addResidencyApplication(residencyApplicationEditEntity: ResidencyApplicationEditEntity): Flow<Res<ResidencyApplicationEntityItem>> = flow {
        emit(api.addResidencyApplication(residencyApplicationEditEntity))
    }.flowOn(Dispatchers.IO)
    fun getResidencyApplicationDetailById(id: Int): Flow<Res<ResidencyApplicationEntityItem>> = flow {
        emit(api.getResidencyApplicationDetailById(id))
    }.flowOn(Dispatchers.IO)
    fun approveResidencyApplication(id: Int): Flow<Res<ResidencyApplicationEntityItem>> = flow {
        emit(api.approveResidencyApplication(id))
    }.flowOn(Dispatchers.IO)
    fun rejectResidencyApplication(id: Int): Flow<Res<ResidencyApplicationEntityItem>> = flow {
        emit(api.rejectResidencyApplication(id))
    }.flowOn(Dispatchers.IO)


}